package com.ruoyi.loan.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.loan.domain.TbRefund;
import com.ruoyi.loan.service.ITbRefundService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 本息方式Controller
 * 
 * @author jy
 * @date 2023-01-14
 */
@RestController
@RequestMapping("/refund")
public class TbRefundController extends BaseController
{
    @Autowired
    private ITbRefundService tbRefundService;

    /**
     * 查询本息方式列表
     */
    @RequiresPermissions("system:refund:list")
    @GetMapping("/list")
    public TableDataInfo list(TbRefund tbRefund)
    {
        startPage();
        List<TbRefund> list = tbRefundService.selectTbRefundList(tbRefund);
        return getDataTable(list);
    }

    /**
     * 导出本息方式列表
     */
    @Log(title = "还款方式", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbRefund tbRefund)
    {
        List<TbRefund> list = tbRefundService.selectTbRefundList(tbRefund);
        ExcelUtil<TbRefund> util = new ExcelUtil<TbRefund>(TbRefund.class);
        util.exportExcel(response, list, "还款方式数据");
    }

    /**
     * 获取本息方式详细信息
     */
    @GetMapping(value = "/getRefund/{refundId}")
    public AjaxResult getInfo(@PathVariable("refundId") Long refundId)
    {
        return success(tbRefundService.selectTbRefundByRefundId(refundId));
    }

    /**
     * 新增本息方式
     */
    @Log(title = "还款方式", businessType = BusinessType.INSERT)
    @PostMapping("/addRefund")
    public AjaxResult add(@RequestBody TbRefund tbRefund)
    {
        return toAjax(tbRefundService.insertTbRefund(tbRefund));
    }

    /**
     * 修改本息方式
     */
    @Log(title = "还款方式", businessType = BusinessType.UPDATE)
    @PutMapping("/updateRefund")
    public AjaxResult edit(@RequestBody TbRefund tbRefund)
    {
        return toAjax(tbRefundService.updateTbRefund(tbRefund));
    }

    /**
     * 删除本息方式
     */
    @RequiresPermissions("system:refund:remove")
    @Log(title = "还款方式", businessType = BusinessType.DELETE)
	@DeleteMapping("/delRefund/{refundIds}")
    public AjaxResult remove(@PathVariable Long[] refundIds)
    {
        return toAjax(tbRefundService.deleteTbRefundByRefundIds(refundIds));
    }
}
